
import java.io.*;
import javax.microedition.lcdui.*;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Bacalá
 */
class MyCanvas extends Canvas implements Runnable  {

    private int maxX, maxY, x, y;
    private int passoX = 1, passoY = 1;
    private Image imagem=null;

    public MyCanvas() {
        try {
            imagem = Image.createImage("/bola.png");


        } catch (IOException ex) {
            ex.printStackTrace();
        }

        maxX = getWidth();
        maxY = getHeight();
        x = maxX / 2;
        y = maxY / 2;
        Thread t = new Thread(this);
        t.start();
    }

    protected void paint(Graphics g) {
        g.setColor(255, 255, 255);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(255, 0, 0);
        g.drawString("TESTANDO", 50,50, Graphics.LEFT | Graphics.TOP);
        g.drawImage(imagem, x, y,Graphics.HCENTER | Graphics.VCENTER);
    }

    public void run() {
        while (true) {
            mexe();
            repaint();
            try {
                Thread.sleep(10);
            } catch (InterruptedException ex) {
                ex.printStackTrace();
            }
        }
    }

    private void mexe() {
        x+=passoX;
        if (x>(maxX-15) || x < 15) passoX=-passoX;
        y+=passoY;
        if (y>maxY-30 || y < 15) passoY=-passoY;
    }
}
